package com.example.java250919_spring_principle.component;

import com.example.java250919_spring_principle.config.BeanConfig;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

@Component
public class BeanLifeComponent implements BeanNameAware, BeanPostProcessor {
    @Autowired
    private BeanConfig beanConfig;

    //1.
    public BeanLifeComponent(){
        System.out.println("执行构造方法");
    }

    //2.
    public void setBeanConfig(BeanConfig beanConfig){
        this.beanConfig = beanConfig;
        System.out.println("执行setter方法");
    }

    //3.
    @Override
    public void setBeanName(String name) {
        System.out.println("执行BeanNameAware.setBeanName,name:"+name);
    }

    //4.
    @PostConstruct
    public void init(){
        System.out.println("执行init方法...");
    }

    //6.
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行postProcessAfterInitialization...");
        return bean;
    }

    //5.
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行postProcessBeforeInitialization...");
        return bean;
    }

    //7.
    public void use(){
        System.out.println("执行use 方法");
    }

    //8.
    @PreDestroy
    public void destroy(){
        System.out.println("执行destroy方法");
    }


}















































